/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interfaz;

import Negocio.Llamadas;
import Negocio.NEmergencias;
import Negocio.NInstituciones;
import Negocio.ServiciosProblemas;
import Patrones.CategoriaUrgencia;
import ecu911.ClaseServicios;
import java.awt.Checkbox;
import java.awt.Color;
import java.awt.PopupMenu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;
import javax.swing.DefaultCellEditor;
import javax.swing.DefaultListModel;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.Timer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author Marcelo Montaño
 */
public class Menu extends javax.swing.JFrame {

    JComboBox comboDirecciones; //combo para las direcciones
    JComboBox comboInstituciones; //combo para las instituciones de emergencia
    
    JCheckBox checkSeleccionar;
    
    int filasTabla = -1; //para incrementar las filas de la tabla
    
    DefaultTableModel modeloTabla;
    DefaultListModel modeloLista;
    ArrayList listaInstituciones;
    ArrayList listaLlamadas;
    ArrayList listaSolicitantes;
    ArrayList listaEmergencias;
    ArrayList listaServiciosProblemas = new ArrayList();
    ClaseServicios usuarioSistema = new ClaseServicios();
    
    Vector vectorSeleccion = new Vector();
    
    public Timer objetotimer;
    public int a;
    
    /**
     * Creates new form Menu
     */
    public Menu() {
        initComponents();
        this.getContentPane().setBackground(Color.white);
        this.btnGuardarLlamada.setBackground(Color.white);
        this.btnInstituciones.setBackground(Color.white);
        this.btnSalir.setBackground(Color.white);
        this.listaInstitucionesSeleccionadas.setSelectionBackground(Color.red);
        this.soloLetras(this.txtNombres);
        this.soloLetras(this.txtApellidos);
        this.soloNumeros(this.txtCedula);
        this.soloNumeros(this.txtTelefono);
        this.txtFecha.setEditable(false);
        this.txtHora.setEditable(false);
        this.txtUsuarioActivo.setEditable(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        jToolBar1 = new javax.swing.JToolBar();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        jLabel15 = new javax.swing.JLabel();
        txtUsuarioActivo = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        jLabel16 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        txtApellidos = new javax.swing.JTextField();
        txtTelefono = new javax.swing.JTextField();
        txtCedula = new javax.swing.JTextField();
        txtNombres = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        txtFecha = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtHora = new javax.swing.JTextField();
        cmbEmergencias = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        cmbSectores = new javax.swing.JComboBox();
        btnEmergencias = new javax.swing.JButton();
        btnSectores = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        txtDireccion = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaEmergenciasActuales = new javax.swing.JTable();
        jPanel5 = new javax.swing.JPanel();
        btnSalir = new javax.swing.JButton();
        btnGuardarLlamada = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        btnInstituciones = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        listaInstitucionesSeleccionadas = new javax.swing.JList();
        barra = new javax.swing.JProgressBar();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(255, 102, 0));

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel14.setForeground(new java.awt.Color(255, 255, 255));
        jLabel14.setText("Atención de llamadas de emergencia, todos los datos son necesarios.");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel14)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(20, Short.MAX_VALUE)
                .addComponent(jLabel14)
                .addContainerGap())
        );

        jToolBar1.setRollover(true);
        jToolBar1.add(jSeparator3);

        jLabel15.setText("Usuario:");
        jToolBar1.add(jLabel15);
        jToolBar1.add(txtUsuarioActivo);
        jToolBar1.add(jSeparator2);

        jLabel16.setBackground(new java.awt.Color(255, 255, 255));
        jLabel16.setForeground(new java.awt.Color(153, 0, 0));
        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/16 (Edit-2).gif"))); // NOI18N
        jLabel16.setText("Editar");
        jLabel16.setToolTipText("Editar informaci[on usuario.");
        jLabel16.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jToolBar1.add(jLabel16);

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Información solicitante."));

        jLabel5.setText("Teléfono/Móvil:");

        jLabel2.setText("Cédula:");

        jLabel4.setText("Apellidos:");

        jLabel3.setText("Nombres:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtNombres, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE)
                        .addComponent(txtApellidos))
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtNombres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Información llamada de urgencia."));

        jLabel7.setText("Fecha:");

        jLabel8.setText("Hora:");

        jLabel9.setText("Emergencia:");

        cmbEmergencias.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cmbEmergenciasMouseClicked(evt);
            }
        });
        cmbEmergencias.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbEmergenciasActionPerformed(evt);
            }
        });

        jLabel10.setText("Sector:");

        btnEmergencias.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/Add.gif"))); // NOI18N
        btnEmergencias.setToolTipText("Agregar tipo emergencia");
        btnEmergencias.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEmergenciasActionPerformed(evt);
            }
        });

        btnSectores.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/Add.gif"))); // NOI18N
        btnSectores.setToolTipText("Agregar sector");
        btnSectores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSectoresActionPerformed(evt);
            }
        });

        jLabel11.setText("Dirección:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(txtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(113, 113, 113)
                                .addComponent(jLabel8)
                                .addGap(18, 18, 18)
                                .addComponent(txtHora, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(cmbSectores, 0, 358, Short.MAX_VALUE)
                                .addComponent(cmbEmergencias, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(btnSectores, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(btnEmergencias, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addGap(18, 18, 18)
                        .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(1, 1, 1)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(txtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9)
                        .addComponent(cmbEmergencias, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnEmergencias))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel10)
                        .addComponent(cmbSectores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnSectores))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Historial llamadas usuario."));

        tablaEmergenciasActuales.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Fecha", "Hora", "Tipo Emergencia", "Dirección", "Solicitante"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tablaEmergenciasActuales);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));
        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btnSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/salir.jpg"))); // NOI18N
        btnSalir.setToolTipText("Salir sistema");
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });

        btnGuardarLlamada.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/guardar.jpg"))); // NOI18N
        btnGuardarLlamada.setToolTipText("Guardar llamada");
        btnGuardarLlamada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarLlamadaActionPerformed(evt);
            }
        });

        btnInstituciones.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/instituciones.jpg"))); // NOI18N
        btnInstituciones.setToolTipText("Instituciones de Auxilio");
        btnInstituciones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInstitucionesActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnGuardarLlamada, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(btnInstituciones, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnGuardarLlamada)
                .addGap(16, 16, 16)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnInstituciones, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnSalir)
                .addContainerGap())
        );

        jPanel6.setBackground(new java.awt.Color(255, 255, 255));
        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Instituciones de atención."));

        jScrollPane3.setViewportView(listaInstitucionesSeleccionadas);

        jLabel1.setText("Peligrosidad de la Llamada:");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(barra, javax.swing.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 307, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(barra, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 333, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(79, 79, 79))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(4, 4, 4)))
                .addGap(11, 11, 11)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-1305)/2, (screenSize.height-701)/2, 1305, 701);
    }// </editor-fold>//GEN-END:initComponents

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_btnSalirActionPerformed

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        // TODO add your handling code here:
        LoginUsuario login =  new LoginUsuario(this, true);
        if(!login.usuarioActivo.isEmpty()){
            txtUsuarioActivo.setText(login.usuarioActivo.get(1).toString() + " " + login.usuarioActivo.get(2).toString());
        }
        //llenarComboEmergencias();
        //llenarComboSectores();
        //this.llenarLista();
    }//GEN-LAST:event_formWindowActivated

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        llenarComboEmergencias();
        llenarComboSectores();
        //this.llenarLista();
        this.txtFecha.setText(this.capturarFecha());
        this.txtHora.setText(this.capturarHora());
        this.cargarTablaLlamadasUsuario();
    }//GEN-LAST:event_formWindowOpened

    private void btnEmergenciasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEmergenciasActionPerformed
        // TODO add your handling code here:
        Interfaz.Emergencias emergencia = new Interfaz.Emergencias(this, true);
        emergencia.setVisible(true);
        
    }//GEN-LAST:event_btnEmergenciasActionPerformed

    private void btnSectoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSectoresActionPerformed
        // TODO add your handling code here:
        Sectores sector = new Sectores(this, true);
        sector.setVisible(true);
    }//GEN-LAST:event_btnSectoresActionPerformed

    private void btnInstitucionesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInstitucionesActionPerformed
        // TODO add your handling code here:
        Instituciones emergencia = new Instituciones(this, true);
        emergencia.setVisible(true);
    }//GEN-LAST:event_btnInstitucionesActionPerformed

    private void btnGuardarLlamadaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarLlamadaActionPerformed
        // TODO add your handling code here:
        if (this.validarCamposTextoCompleto()){    
            boolean registroAceptado =  false;
            ArrayList respuesta = new ArrayList();
            //******** GUARDO SOLICITANTE **************************************************************
            respuesta = usuarioSistema.crearSolicitante(txtCedula.getText(), //cedula ingresada
                                                         txtNombres.getText().toUpperCase(), //nombre ingresado
                                                         txtApellidos.getText().toUpperCase(), //apellido ingresado
                                                         txtTelefono.getText());  //estado por default
            if(respuesta.get(0).equals("true")){
                registroAceptado = true;
            }

            //**********  GUARDO LLAMADA ***********************************************************
            respuesta.clear();
            ArrayList numeroRegistroLlamadas = new ArrayList();
            numeroRegistroLlamadas = usuarioSistema.listadoLlamadas();
            String idLlamada = String.valueOf(numeroRegistroLlamadas.size()+1);
            respuesta = usuarioSistema.crearLlamada(idLlamada , 
                                                    txtCedula.getText().toUpperCase(), //nombre ingresado
                                                    txtDireccion.getText().toUpperCase(), //apellido ingresado
                                                    txtFecha.getText(),
                                                    txtHora.getText(),
                                                    String.valueOf(cmbSectores.getSelectedIndex()+1),
                                                    String.valueOf(cmbEmergencias.getSelectedItem()));  //estado por default
            if(respuesta.get(0).equals("true")){
                registroAceptado = true;
            }
            //********************* GUARDO INSTITUCIONES SELECCIONADAS *****************************
            respuesta.clear();
            if (vectorSeleccion.size() > 0){
                for (int i=0; i<vectorSeleccion.size(); i++)
                {
                    respuesta = usuarioSistema.crearLlamadaInstitucion(idLlamada,
                                                                   String.valueOf(i+1));
                    if(respuesta.get(0).equals("true")){
                        registroAceptado = true;
                    }
                } 
            }

            if (registroAceptado){
                JOptionPane.showConfirmDialog(null,"Llamada atendida.",
                "Atender llamada",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE,null); 
                this.cargarTablaLlamadasUsuario();
            }
            else{
                JOptionPane.showConfirmDialog(null,"El registro no se puedo almacenar.",
                "Error",JOptionPane.DEFAULT_OPTION,JOptionPane.ERROR_MESSAGE,null); 
            }
        }
        else{
            JOptionPane.showConfirmDialog(null,"Complete toda la información.",
                "Error",JOptionPane.DEFAULT_OPTION,JOptionPane.ERROR_MESSAGE,null);
            this.pintarTextosVacios();
        }
    }//GEN-LAST:event_btnGuardarLlamadaActionPerformed

    private void cmbEmergenciasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmbEmergenciasMouseClicked
        // TODO add your handling code here:
        
    }//GEN-LAST:event_cmbEmergenciasMouseClicked

    private void cmbEmergenciasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbEmergenciasActionPerformed
        // TODO add your handling code here:
        //System.out.println(this.cmbEmergencias.getSelectedIndex());
        ClaseServicios cliente =  new ClaseServicios();
        listaServiciosProblemas = usuarioSistema.listadoServiciosProblemas();
        listaInstituciones = cliente.listadoServicios();
        Vector v = new Vector();
        Vector v2 = new Vector();
        this.listaInstitucionesSeleccionadas.setListData(v);
        ServiciosProblemas miSP = new ServiciosProblemas();
        NInstituciones miI = new NInstituciones();
        for (int i = 0; i<listaServiciosProblemas.size(); i++){
            miSP = (ServiciosProblemas)listaServiciosProblemas.get(i);
            if(miSP.getIdProblema().toString().compareTo(String.valueOf(this.cmbEmergencias.getSelectedIndex()+1))==0)
            {
                v.add(miSP.getIdServicio());
            }
        }
        for (int i = 0; i<v.size(); i++){
            v2.add(listaInstituciones.get(i));
        }
        this.listaInstitucionesSeleccionadas.setListData(v2);
        this.llenarBarraCategoria(v2.size());
        
    }//GEN-LAST:event_cmbEmergenciasActionPerformed

    private void llenarBarraCategoria(int tam){
        //System.out.println(tam);
        CategoriaUrgencia categoria = new CategoriaUrgencia();
        String cat = categoria.verificarCategoriaUrgencia(tam);
        //System.out.println(cat);
        if (cat.compareTo("A")==0)
        {
            objetotimer = new Timer(80,new claseTimerA());
            objetotimer.start();
            this.barra.setForeground(Color.yellow);
        }
        if (cat.compareTo("B")==0)
        {
            objetotimer = new Timer(80,new claseTimerB());
            objetotimer.start();
            this.barra.setForeground(Color.green);
        }
        if (cat.compareTo("C")==0)
        {
            objetotimer = new Timer(80,new claseTimerC());
            objetotimer.start();
            this.barra.setForeground(Color.red);
        }
        
    }
    
     public class claseTimerA implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
          a=barra.getValue();
          if (a<25){
              a+=5;
              barra.setValue(a);
               }
          else{
              objetotimer.stop();
          }                  
        }
     }
     
     public class claseTimerB implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
          a=barra.getValue();
          if (a<50){
              a+=5;
              barra.setValue(a);
               }
          else{
              objetotimer.stop();
          }                  
       }
     }
     
     public class claseTimerC implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
          a=barra.getValue();
          if (a<100){
              a+=5;
              barra.setValue(a);
               }
          else{
              objetotimer.stop();
          }                  
        }
     }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Menu().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JProgressBar barra;
    private javax.swing.JButton btnEmergencias;
    private javax.swing.JButton btnGuardarLlamada;
    private javax.swing.JButton btnInstituciones;
    private javax.swing.JButton btnSalir;
    private javax.swing.JButton btnSectores;
    private javax.swing.JComboBox cmbEmergencias;
    private javax.swing.JComboBox cmbSectores;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JList listaInstitucionesSeleccionadas;
    private javax.swing.JTable tablaEmergenciasActuales;
    private javax.swing.JTextField txtApellidos;
    private javax.swing.JTextField txtCedula;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtFecha;
    private javax.swing.JTextField txtHora;
    private javax.swing.JTextField txtNombres;
    private javax.swing.JTextField txtTelefono;
    private javax.swing.JTextField txtUsuarioActivo;
    // End of variables declaration//GEN-END:variables

    private void componentesOff() {
        this.txtCedula.setEnabled(false);
        this.txtNombres.setEnabled(false);
        this.txtApellidos.setEnabled(false);
        this.txtTelefono.setEnabled(false);
        this.txtFecha.setEnabled(false);
        this.txtHora.setEnabled(false);
        this.cmbEmergencias.setEnabled(false);
        this.cmbSectores.setEnabled(false);
        this.txtDireccion.setEnabled(false);
        this.tablaEmergenciasActuales.setEnabled(false);
        
    }

    private void componentesOn() {
        this.txtCedula.setEnabled(true);
        this.txtNombres.setEnabled(true);
        this.txtApellidos.setEnabled(true);
        this.txtTelefono.setEnabled(true);
        this.txtFecha.setEnabled(true);
        this.txtHora.setEnabled(true);
        this.cmbEmergencias.setEnabled(true);
        this.cmbSectores.setEnabled(true);
        this.txtDireccion.setEnabled(true);
        this.tablaEmergenciasActuales.setEnabled(true);
        
    }

//    private void llenarLista() {
//        listaInstituciones = usuarioSistema.listadoServicios();
//        Vector v = new Vector();
//        for (int i = 0; i<listaInstituciones.size(); i++){
//            v.add(listaInstituciones.get(i).toString());
//        }
//        this.listaInstitucionesCreadas.setListData(v);
//    }

    private void llenarComboEmergencias() {
        ArrayList listaEmergencias = new ArrayList();
        listaEmergencias = usuarioSistema.listadoProblemas();
        for (int i = 0; i<listaEmergencias.size(); i++){
               this.cmbEmergencias.addItem(listaEmergencias.get(i).toString());
        }
    }
    
    private void llenarComboSectores() {
        ArrayList listaSectores = new ArrayList();
        listaSectores = usuarioSistema.listadoSectores();
        for (int i = 0; i<listaSectores.size(); i++){
               this.cmbSectores.addItem(listaSectores.get(i).toString());
        }
    }
    
    private void soloLetras(JTextField a){
        a.addKeyListener(new KeyAdapter(){
            public void keyTyped(KeyEvent e){
                char c = e.getKeyChar();
                if(Character.isDigit(c)){
                    getToolkit().beep();
                    e.consume();
                }
            }
        }
                );
        
    }

    private void soloNumeros(JTextField a){
        a.addKeyListener(new KeyAdapter(){
            public void keyTyped(KeyEvent e){
                char c = e.getKeyChar();
                if(Character.isLetter(c)){
                    getToolkit().beep();
                    e.consume();
                }
            }
        }
                );
        
    }
      
   private String capturarFecha(){
       Date fecha = new Date();
       SimpleDateFormat formatoFecha = new SimpleDateFormat("dd/mm/yyyy");
       return formatoFecha.format(fecha);
   }

   private String capturarHora(){
       Calendar cal = Calendar.getInstance();
       String hora;
       hora = cal.get(cal.HOUR_OF_DAY) + ":" + cal.get(cal.MINUTE) + ":" + cal.get(cal.SECOND);
       return hora;
   }
   
   private boolean validarCamposTextoCompleto(){
       boolean check = true;
       if(this.txtCedula.getText().compareTo("")==0 ||
          this.txtNombres.getText().compareTo("")==0 ||
          this.txtApellidos.getText().compareTo("")==0 ||
          this.txtDireccion.getText().compareTo("")==0 ||
          this.txtTelefono.getText().compareTo("")==0){
           check = false;
       }
       return check;
   }
   
   private boolean validarSeleccionInstituciones(){
       boolean check = true;
       if(this.vectorSeleccion.size()==0){
           check = false;
       }
       return check;
   }
   
   private void pintarTextosVacios(){
       if(this.txtCedula.getText().compareTo("")==0){
           this.txtCedula.setBackground(Color.yellow);
       }
       else{
           this.txtCedula.setBackground(Color.white);
       }
       if(this.txtNombres.getText().compareTo("")==0){
           this.txtNombres.setBackground(Color.yellow);
       }
       else{
           this.txtNombres.setBackground(Color.white);
       }
       if(this.txtApellidos.getText().compareTo("")==0){
           this.txtApellidos.setBackground(Color.yellow);
       }
       else{
           this.txtApellidos.setBackground(Color.white);
       }
       if(this.txtDireccion.getText().compareTo("")==0){
           this.txtDireccion.setBackground(Color.yellow);
       }
       else{
           this.txtDireccion.setBackground(Color.white);
       }
       if(this.txtTelefono.getText().compareTo("")==0){
           this.txtTelefono.setBackground(Color.yellow);
       }
       else{
           this.txtTelefono.setBackground(Color.white);
       }
       if (this.listaInstitucionesSeleccionadas.getModel().getSize()==0){
           this.listaInstitucionesSeleccionadas.setBackground(Color.yellow);
       }
       else{
           this.listaInstitucionesSeleccionadas.setBackground(Color.white);
       }
   }
   
   private void cargarTablaLlamadasUsuario(){
       ClaseServicios servicio = new ClaseServicios();
       Object nuevo[]= {"","","","",""};
       listaLlamadas = servicio.listadoLlamadas();
       Llamadas miLlamada = new Llamadas();
       modeloTabla = (DefaultTableModel)this.tablaEmergenciasActuales.getModel();
       for (int i = 0; i < listaLlamadas.size(); i++){
           miLlamada = (Llamadas)listaLlamadas.get(i);
           modeloTabla.addRow(nuevo);
           modeloTabla.setValueAt(miLlamada.getFecha().toString(), i, 0);
           modeloTabla.setValueAt(miLlamada.getHora().toString(), i, 1);
           modeloTabla.setValueAt(miLlamada.getIdSector().toString(), i, 2);
           modeloTabla.setValueAt(miLlamada.getDireccion().toString(), i, 3);
           modeloTabla.setValueAt(miLlamada.getIdSolicitante().toString(), i, 4);
       }
   }
}

